import { http } from '@/utils/request'
import type { LoginRequest, RegisterRequest, User, ApiResponse, GuestLoginResponse } from '@/types'

// 用户登录
export const login = (data: LoginRequest): Promise<ApiResponse<{
  user: User;
  token: string;
  refreshToken: string;
}>> => {
  return http.post('/client/auth/login', data)
}

// 游客登录
export const guestLogin = (): Promise<ApiResponse<GuestLoginResponse>> => {
  return http.post('/client/auth/guest-login')
}

// 用户注册
export const register = (data: RegisterRequest): Promise<ApiResponse<{
  user: User;
  token: string;
  refreshToken: string;
}>> => {
  return http.post('/client/auth/register', data)
}

// 用户登出
export const logout = (): Promise<ApiResponse<null>> => {
  return http.post('/client/auth/logout')
}

// 刷新token
export const refreshToken = (refreshToken: string): Promise<ApiResponse<{
  token: string;
  refreshToken: string;
}>> => {
  return http.post('/client/auth/refresh', { refreshToken })
}

// 获取用户信息
export const getProfile = (): Promise<ApiResponse<User>> => {
  return http.get('/client/auth/profile')
}

// 修改密码
export const changePassword = (data: {
  currentPassword: string;
  newPassword: string;
}): Promise<ApiResponse<null>> => {
  return http.put('/client/auth/change-password', data)
} 